package com.qlujavateam.service;

import java.util.List;

import com.qlujavateam.sqloperation.ToTeacherClass;
import com.qlujavateam.sqloperation.ToTeacher;
import com.qlujavateam.methods.Teacher;

/*
 * 教师业务逻辑类
 *
 */
public class TeacherService {

	private ToTeacher tdao = new ToTeacher();
	private ToTeacherClass tcdao = new ToTeacherClass();

	/*
	 * 老师登录的逻辑
	 *
	 */
	public Teacher teacherLogin(String tname, String tpass) {

		Teacher t = tdao.queryByTeacherPhone(tname);

		if (t == null) {// 如果老师没有找到
			throw new RuntimeException("查无此人");// java强大的异常处理机制
		}

		// 表示数据库的密码和输入的密码不一致
		if (!t.getTpassword().equals(tpass)) {
			throw new RuntimeException("用户名或者密码错误");// java强大的异常处理机制
		}

		return t;

	}

	/*
	 * 查询老师所有的数据
	 *
	 */
	public List<Teacher> queryAll() {
		String sql = "select * from teacher";
		return tdao.queryAll();

	}

	public List<Teacher> queryClassTeacher(String sno) {
		return tdao.queryClassTeacher(sno);
	}

}
